package com.cw.jeeyt.service.converter.git;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.cw.jeeyt.service.bo.git.GitBranchBo;
import com.cw.jeeyt.dao.model.git.GitBranchDo;
import com.cw.lang.common.utils.CollectionUtil;

/**
 * git项目分支信息转换类
 *
 * @author chenw
 * @date 2019-04-08 21:44:19
 */
public class GitBranchConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static GitBranchBo do2Bo(GitBranchDo model) {
        GitBranchBo bo = new GitBranchBo();
        if (model == null) {
            return bo;
        }
        bo.setId(model.getId());
        bo.setProjectId(model.getProjectId());
        bo.setBranchCode(model.getBranchCode());
        bo.setBranchName(model.getBranchName());
        return bo;
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static GitBranchDo bo2Do(GitBranchBo bo) {
        GitBranchDo model = new GitBranchDo();
        if (bo == null) {
            return model;
        }
        model.setId(bo.getId());
        model.setProjectId(bo.getProjectId());
        model.setBranchCode(bo.getBranchCode());
        model.setBranchName(bo.getBranchName());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<GitBranchBo> doList2BoList(List<GitBranchDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), GitBranchConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<GitBranchDo> boList2DoList(List<GitBranchBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), GitBranchConverter::bo2Do));
    }
}